﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class PartyFindBranch : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            PartyFindBranchOutParam result = new PartyFindBranchOutParam();
            PartyFindBranchInParam param = new PartyFindBranchInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as PartyFindBranchInParam;
                if (string.IsNullOrEmpty(param.Name) || string.IsNullOrEmpty(param.Sex) || string.IsNullOrEmpty(param.IDNum)
                    || string.IsNullOrEmpty(param.contact) || string.IsNullOrEmpty(param.branchId) || string.IsNullOrEmpty(param.street))
                {
                    result.code = "0";
                    result.desc = "姓名,性别,身份证号码,手机号码,党组织ID,街道不能为空";

                    isFlag = false;
                }
                string age = "0";
                try
                {
                    age = (DateTime.Now.Year - Convert.ToDateTime(param.birth).Year).ToString();
                }
                catch
                {
                    result.code = "0";
                    result.desc = "出生年月格式不正确";

                    isFlag = false;
                }

                if(isFlag)
                {
                    //获取党务工作者 
                    string branchUser = InterfaceHelper.GetBranchLeader(InterfaceHelper.GetstreetBranchID(param.street));
                    string id = StringHelper.NewID;


                    InterfaceHelper.PartyFindBranch(param.Name, param.Sex, param.IDNum, param.QQ, param.ReAddress, param.contact, param.branchId, param.FrAddress,
                        param.education, param.Job, param.PartyNum, param.InTime, param.WrAddress, param.birth, age, id);

                    if (!string.IsNullOrEmpty(branchUser))
                    {            //待办
                        InterfaceHelper.AddTask(id, param.Name + "申请",
                            "流动党员找组织", "",
                            new String[] { branchUser },
                            CommonUtils.AppAddress + "admin/Project/BranchCenter/Module/FlowPartyMembers/PartyMembersFindOrgApproval.aspx?RelationID=" + id, "Member");
                    }
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-PartyFindBranchWX", SerializeHelper.JsonSerializer<PartyFindBranchInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<PartyFindBranchInParam, PartyFindBranchOutParam>();
            else
                SafeProcessRequest<PartyFindBranchInParam, PartyFindBranchOutParam>();
        }
    }

    #region 请求参数
    public class PartyFindBranchInParam
    {  
        /// <summary>
        ///	姓名 必须	
        /// </summary>
        public string Name
        { get; set; }
        /// <summary>
        ///	性别 必须	
        /// </summary>
        public string Sex
        { get; set; }
        /// <summary>
        /// 出生年月	
        /// </summary>
        public string birth
        { get; set; }
        /// <summary>
        ///	籍贯	
        /// </summary>
        public string FrAddress
        { get; set; }
        /// <summary>
        ///	身份证号码 必须	
        /// </summary>
        public string IDNum
        { get; set; }
        /// <summary>
        ///	手机号码 必须 	
        /// </summary>
        public string contact
        { get; set; }
        /// <summary>
        ///	QQ号码	
        /// </summary>
        public string QQ
        { get; set; }
        /// <summary>
        ///	民族	
        /// </summary>
        public string nation
        { get; set; }
        /// <summary>
        ///	入党时间	
        /// </summary>
        public string InTime
        { get; set; }
        /// <summary>
        ///	党组织工作所在地	
        /// </summary>
        public string WrAddress
        { get; set; }
        /// <summary>
        ///	居住地址	
        /// </summary>
        public string ReAddress
        { get; set; }
        /// <summary>
        ///	职务	
        /// </summary>
        public string Job
        { get; set; }
        /// <summary>
        ///	学历	
        /// </summary>
        public string education
        { get; set; }
        /// <summary>
        ///	党员编号	
        /// </summary>
        public string PartyNum
        { get; set; }
        /// <summary>
        ///	党组织ID 必须
        /// </summary>
        public string branchId
        { get; set; }
        /// <summary>
        ///	街道
        /// </summary>
        public string street
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class PartyFindBranchOutParam
    {
        public PartyFindBranchOutParam()
        {
            code = "1";
            desc = "操作成功"; 
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; } 
    } 
    #endregion 
}